// 管理地址的仓库
import { requestGet } from "../utils/Request.js";
import { getSession, setSession } from "@/utils/index.js";
export default ({
    namespaced:true,
    state: {
        addressList:getSession('addressList')||[],
        usingAddr:getSession('usingAddr')||null,
        chosenAddrId:getSession('usingAddr')||'',
    },
    mutations: {
        getAddress(state,playload){
            state.addressList=playload
            setSession('addressList',state.addressList)
        },
        setUsingAddr(state,playload){
            state.usingAddr=playload
            setSession('usingAddr',state.usingAddr)
        },
        changeChosenAddr(state,playload){
            state.chosenAddrId=playload
            setSession('chosenAddrId',state.chosenAddrId)
        }
    },
    actions: {
        async getAddress({ commit },playload){
            const res=await requestGet('/address',playload)
            commit('getAddress',res.data.result)
        }
    },
})